/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       script_event.cpp

	$Header: /game/script_event.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "script_event.h"

#include <cassert>

#include "abstract_script_action.h"
#include "script_sequence.h"

// --------------------------------------------------------------------------
// t_script_event members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_event::t_script_event()
	:	m_script_ptr( new t_script_action< k_script_action_sequence > )
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_event::t_script_event( t_script_event const & other )
	:	m_script_ptr( other.m_script_ptr )
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_event::~t_script_event()
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_event::t_script const & t_script_event::get_script() const
{
	assert( m_script_ptr.get() != 0 );
	return *m_script_ptr;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
void t_script_event::set_script( t_script_ptr new_script_ptr )
{
	assert( new_script_ptr.get() != 0 );
	m_script_ptr = new_script_ptr;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_event::read(
	std::streambuf &	stream,
	int					version )
{
	t_script_ptr new_script_ptr = t_script::reconstruct( stream, version );
	if ( new_script_ptr.get() == 0 )
		return false;

	m_script_ptr = new_script_ptr;

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_event::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	t_script_ptr new_script_ptr = t_script::reconstruct_from_map( stream );
	if ( new_script_ptr.get() == 0 )
		return false;

	m_script_ptr = new_script_ptr;

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_event::write( std::streambuf & stream ) const
{
	return m_script_ptr->write( stream );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_event & t_script_event::operator=( t_script_event const & other )
{
	m_script_ptr = other.m_script_ptr;
	return *this;
}
